import Vue from 'vue'
import Vuex from 'vuex'
import {getAdminInfo} from '@/api/getData'

Vue.use(Vuex)

const state = {
	// adminInfo: {
	// 	avatar: 'default.jpg'
	// },
	admin: {
		avatar: 'default.jpg'
	},
}

const getDefaultState = () => {
  return {
  
    name: '',
    avatar: ''
  }
}


const mutations = {
	// saveAdminInfo(state, adminInfo){
	// 	state.adminInfo = adminInfo;
	// },
	saveAdmin(state, adminInfo){
		state.admin = adminInfo;
	},
	RESET_STATE: (state) => {
    Object.assign(state, getDefaultState())
  },
	
}

const actions = {

	async getAdmin({commit}){
		try{
			if(localStorage.getItem('admin') != null){
				commit('saveAdmin', JSON.parse(localStorage.getItem('admin')));
			}
		
		}catch(err){
			// console.log(err.message)
		}
	},



}

export default new Vuex.Store({
	state,
	actions,
	mutations,
})
